package com.ruoyi.sl.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.domain.entity.SlSsm;
import com.ruoyi.sl.service.ISlSsmService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 计薪方式Controller
 * 
 * @author admin
 * @date 2024-06-03
 */
@RestController
@RequestMapping("/sl/ssm")
public class SlSsmController extends BaseController
{
    @Autowired
    private ISlSsmService slSsmService;

    /**
     * 查询计薪方式列表
     */
    @PreAuthorize("@ss.hasPermi('sl:ssm:list')")
    @GetMapping("/list")
    public TableDataInfo list(SlSsm slSsm)
    {
        startPage();
        List<SlSsm> list = slSsmService.selectSlSsmList(slSsm);
        return getDataTable(list);
    }

    /**
     * 导出计薪方式列表
     */
    @PreAuthorize("@ss.hasPermi('sl:ssm:export')")
    @Log(title = "计薪方式", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SlSsm slSsm)
    {
        List<SlSsm> list = slSsmService.selectSlSsmList(slSsm);
        ExcelUtil<SlSsm> util = new ExcelUtil<SlSsm>(SlSsm.class);
        util.exportExcel(response, list, "计薪方式数据");
    }

    /**
     * 获取计薪方式详细信息
     */
    @PreAuthorize("@ss.hasPermi('sl:ssm:query')")
    @GetMapping(value = "/{ssmId}")
    public AjaxResult getInfo(@PathVariable("ssmId") Long ssmId)
    {
        return success(slSsmService.selectSlSsmBySsmId(ssmId));
    }

    /**
     * 新增计薪方式
     */
    @PreAuthorize("@ss.hasPermi('sl:ssm:add')")
    @Log(title = "计薪方式", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SlSsm slSsm)
    {
        slSsm.setCreateBy(getUsername());
        return toAjax(slSsmService.insertSlSsm(slSsm));
    }

    /**
     * 修改计薪方式
     */
    @PreAuthorize("@ss.hasPermi('sl:ssm:edit')")
    @Log(title = "计薪方式", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SlSsm slSsm)
    {
        slSsm.setUpdateBy(getUsername());
        return toAjax(slSsmService.updateSlSsm(slSsm));
    }

    /**
     * 删除计薪方式
     */
    @PreAuthorize("@ss.hasPermi('sl:ssm:remove')")
    @Log(title = "计薪方式", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ssmIds}")
    public AjaxResult remove(@PathVariable Long[] ssmIds)
    {
        return toAjax(slSsmService.deleteSlSsmBySsmIds(ssmIds));
    }
}
